home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_PICT / Source / CommentedPSCode / Regions < prev    next >
Text File  |  1995-06-12  |  6KB  |  285 lines

  1. %BEGIN Regions
  2.  
  3. % Copyright (C) 1993 David John Burrowes
  4. % Distributed under terms of GNU General Public License.
  5. % See COPYING.text in Convert PICT's CommentedPSCode for a copy
  6.  
  7. %%%%%%%%%%%%%
  8. %    Note:
  9. %        regionBounds and regionPath is defined in the common file
  10. %        regionInfo is top, left, bot, right coords of bounding rect, followed by the number
  11. %        of shapes.  Each spape is the number of vertices, followed by that many x,y pairs
  12. %        that represent the corners of the shape.
  13. %%%%%%%%%%%%%
  14.  
  15. %%%%%%%%%%%%%
  16. %    Name:    frameRgn            [0080]
  17. %    Syntax:    regionInfo frameRgn -
  18. %    About:    Set up bounds.  If pen sizes > 0 draw two paths.  The outer goes from passed
  19. %            vertex to passed vertex, drawing the outer edge.  The second is inset by the
  20. %            sizes of penWidth and penHeight.  Fill between these to get a frame of right size.
  21. %    Note:    regions w/ holes (e.g. 'doughnuts') may not have the holes framed precisely
  22. %            correctly.  This will inset the frame of the hole, but perhaps the mac does not.
  23. %%%%%%%%%%%%%
  24. /frameRgn
  25. {
  26.     gsave
  27.         penPattern usePattern
  28.         /tempRight exch def
  29.         /tempBottom exch def
  30.         /tempLeft exch def
  31.         /tempTop exch def
  32.         /numShapes exch def
  33.         numShapes 0 eq
  34.         {
  35.             %
  36.             %    No shapes, frame the bounding rect.  (do this by building a
  37.             %    'fake' region shape for following routines to consume
  38.             %
  39.             tempLeft tempTop tempRight tempTop
  40.             tempRight tempBottom tempLeft  tempBottom
  41.             4
  42.             /numShapes 1 def
  43.         }
  44.         {
  45.             tempTop tempLeft tempBottom tempRight regionBounds
  46.             clip
  47.         }
  48.         ifelse
  49.  
  50.         penWidth 0 le
  51.         penHeight 0 le
  52.         or
  53.         {
  54.             %
  55.             %    Consume & discard coordinates, using the passed counts for the repeat
  56.             %
  57.             numShapes
  58.             {
  59.                 { pop pop }
  60.                 repeat
  61.             }
  62.             repeat
  63.         }
  64.         {
  65.             %
  66.             %    For each of the shapes, read in verticees and draw lines between
  67.             %    then, make a second pass over points, drawing inner path
  68.             %
  69.             newpath
  70.             numShapes
  71.             {
  72.                 /numCoords exch 2 mul def
  73.                 /ptArray  numCoords array def
  74.                 /firsty exch def
  75.                 /firstx exch def
  76.                 %
  77.                 %    Form the outer edge of shape, storing points in array
  78.                 %
  79.                 firstx firsty  moveto
  80.                 0 2 numCoords 3 sub    % 3 is for: zero origin, and skipped first coords
  81.                 {
  82.                     /arrayIndex exch def
  83.                     /y1 exch def
  84.                     /x1 exch def
  85.                     ptArray arrayIndex x1 put
  86.                     ptArray arrayIndex 1 add y1 put
  87.                     x1 y1 lineto
  88.                 }
  89.                 for
  90.                 closepath
  91.                 %
  92.                 %    Compute inner edge.  While inset by pen size, we must put vertices
  93.                 %    in non straightforward position.  lastx was the x coord of last vertex
  94.                 %    we saw.  thisx is the x of the current vertex.  pendx is the x coordinate
  95.                 %    that is proposed for the vertex to be drawn that cooresponds to the lastx
  96.                 %    This is because we can not definitely figure out where point N's inset
  97.                 %    coords are without knowing where point N+1 is.  Do a couple examples.
  98.                 %    NOTE: We trap for case where only 1 line segment (4 coords) in region.
  99.                 /pendx firstx penWidth add def
  100.                 numCoords 4  gt
  101.                 {
  102.                     ptArray 2 get pendx lt
  103.                         { /pendy firsty penHeight add def }
  104.                         { /pendy firsty penHeight sub def }
  105.                     ifelse
  106.                  }
  107.                 { /pendy firsty penHeight sub def  }
  108.                 ifelse
  109.                 /lastx ptArray 0 get   def
  110.                 /lasty ptArray 1 get  def
  111.                 pendx pendy  moveto
  112.                 2 4  numCoords 5 sub
  113.                 {
  114.                     /arrayIndex exch def
  115.  
  116.                     /thisx ptArray arrayIndex get   def
  117.                     /thisy ptArray arrayIndex 1 add get  def
  118.                     %
  119.                     %    If thisy - lasty > 0, pendx = lastx + penWidth
  120.                     %
  121.                     /pendx lastx penWidth
  122.                         thisy lasty sub 0 gt {add}  {sub} ifelse
  123.                     def
  124.                     pendx pendy  lineto
  125.                     /lastx thisx def
  126.                     /lasty thisy def
  127.  
  128.                     /thisx ptArray arrayIndex 2 add get   def
  129.                     /thisy ptArray arrayIndex 3 add get  def
  130.                     /pendy lasty penHeight
  131.                         thisx lastx sub 0 gt {sub}  {add } ifelse
  132.                     def
  133.                     pendx pendy  lineto
  134.                     /lasty thisy def
  135.                     /lastx thisx def
  136.  
  137.                 }
  138.                 for
  139.                 firstx penWidth add pendy  lineto
  140.                 closepath
  141.             }
  142.             repeat
  143.             eofill
  144.         }
  145.         ifelse
  146.     grestore
  147. }
  148. def
  149.  
  150. %%%%%%%%%%%%%
  151. %    Name:    paintRgn            [0081]
  152. %    Syntax:    regionInfo paintRgn -
  153. %    About:    Fill the passed region with the pen pattern (use eofill because there
  154. %            may be shapes within shapes all drawn in same direction). Note:
  155. %            If there are no shapes, we just fill the 'bounding' rect.
  156. %%%%%%%%%%%%%
  157. /paintRgn
  158. {
  159.     gsave
  160.         penPattern usePattern
  161.         regionBounds
  162.         /numShapes exch def
  163.         numShapes 0 eq
  164.         { fill }
  165.         {
  166.             clip
  167.             numShapes  regionPath
  168.             eofill
  169.         }
  170.         ifelse
  171.     grestore
  172. }
  173. def
  174.  
  175. %%%%%%%%%%%%%
  176. %    Name:    eraseRgn            [0082]
  177. %    Syntax:    regionInfo eraseRgn -
  178. %    About:    Fill the passed region with the background pattern (use eofill because there
  179. %            may be shapes within shapes all drawn in same direction). Note:
  180. %            If there are no shapes, we just fill the 'bounding' rect.
  181. %%%%%%%%%%%%%
  182. /eraseRgn
  183. {
  184.     gsave
  185.         backPattern usePattern
  186.         regionBounds
  187.         /numShapes exch def
  188.         numShapes 0 eq
  189.         { fill }
  190.         {
  191.             clip
  192.             numShapes  regionPath
  193.             eofill
  194.         }
  195.         ifelse
  196.     grestore
  197. }
  198. def
  199.  
  200.  
  201. %%%%%%%%%%%%%
  202. %    Name:    invertRgn            [0083]
  203. %    Syntax:    regionInfo invertRgn -
  204. %    About:    Consume the region data.  No inversion because we can't easily.
  205. %%%%%%%%%%%%%
  206. /invertRgn
  207. {
  208.     gsave
  209.         regionBounds
  210.         regionPath
  211.     grestore
  212. } def
  213.  
  214. %%%%%%%%%%%%%
  215. %    Name:    fillRgn            [0084]
  216. %    Syntax:    regionInfo fillRgn -
  217. %    About:    Fill the passed region with the fill pattern (use eofill because there
  218. %            may be shapes within shapes all drawn in same direction). Note:
  219. %            If there are no shapes, we just fill the 'bounding' rect.
  220. %%%%%%%%%%%%%
  221. /fillRgn
  222. {
  223.     gsave
  224.         fillPattern usePattern
  225.         regionBounds
  226.         /numShapes exch def
  227.         numShapes 0 eq
  228.         { fill }
  229.         {
  230.             clip
  231.             numShapes  regionPath
  232.             eofill
  233.         }
  234.         ifelse
  235.     grestore
  236. }
  237. def
  238.  
  239. %%%%%%%%%%%%%
  240. %    Name:    frameSameRgn            [0088]
  241. %    Syntax:    - frameSameRgn -
  242. %    About:    Apple doesn't implement this, so nor do I
  243. %%%%%%%%%%%%%
  244. /frameSameRgn
  245.     { }
  246. def
  247.  
  248. %%%%%%%%%%%%%
  249. %    Name:    paintSameRgn            [0089]
  250. %    Syntax:    - paintSameRgn -
  251. %    About:    Apple doesn't implement this, so nor do I
  252. %%%%%%%%%%%%%
  253. /paintSameRgn
  254.     { }
  255. def
  256.  
  257. %%%%%%%%%%%%%
  258. %    Name:    eraseSameRgn            [008A]
  259. %    Syntax:    - eraseSameRgn -
  260. %    About:    Apple doesn't implement this, so nor do I
  261. %%%%%%%%%%%%%
  262. /eraseSameRgn
  263.     { }
  264. def
  265.  
  266. %%%%%%%%%%%%%
  267. %    Name:    invertSameRgn            [008B]
  268. %    Syntax:    - invertSameRgn -
  269. %    About:    Apple doesn't implement this, so nor do I
  270. %%%%%%%%%%%%%
  271. /invertSameRgn
  272.     { }
  273. def
  274.  
  275. %%%%%%%%%%%%%
  276. %    Name:    fillSameRgn            [008C]
  277. %    Syntax:    - fillSameRgn -
  278. %    About:    Apple doesn't implement this, so nor do I
  279. %%%%%%%%%%%%%
  280. /fillSameRgn
  281.     { }
  282. def
  283.  
  284. %END Regions
  285.